<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<h1>ajax-Post请求</h1>
		<script type="text/javascript" src="../js/axios.js"></script>
		<!-- promise是Axios封装服务器返回值的对象 -->
		<script type="text/javascript">
			//1.Axios的优化
			axios.defaults.baseURL = "http://localhost:8080"

			//1.定义一个函数
			async function saveUser() {
				let user = {
					id: 100,
					name: "春节已过",
					age: 20
				}
				let {
					data: result,
					status: code
				} = await axios.post("/axios/saveUser", user)
				console.log(result)
				console.log(code)
				//let Promise = await axios.post("/axios/saveUser",user)
			}
			//2.调用函数
			saveUser()

			//3.箭头函数
			let user2 = {
				id: 200,
				name: "箭头函数"
			}
			axios.post("/axios/saveUser", user2)
				.then(function(promise) {
					console.log(promise.data)
				})
			axios.post("/axios/saveUser", user2)
				.then(promise => {
					console.log(promise.data)
				})








			// let user = {id : 100, name : "tomcat猫", age : 20}
			// axios.post("/axios/saveUser", user)
			// 	 .then(promise => {
			// 		 console.log(promise.data)

			// 	 })
		</script>
	</body>
</html>
